﻿ProductList = {
    NoImage: '../../images/no_image.jpg',
    LoadImage: '../../images/loader.gif',
    Load: function (list, detail) {
        var i, _this = this;
        if (list) {
            var arr = [];
            var $list = $('.product-list'),
                $detail = $list.find('ul.list-item li').clone();
            for (i = 0; i < list.length; i++) {
                var $l = $list.clone();
                $l.find('.ui-header a').attr('href', '?catID=' + list[i].IDKey);
                $l.find('.ui-header a h2').html(list[i].Name);
                $l.find('ul.list-item').attr('id', list[i].IDKey).html('');

                $list.before($l);
            }
            $list.remove();

            if (detail) {
                for (i = 1; i < detail.length; i++) {
                    _this.ShowDetail(detail[i], $detail);
                }
                $('.product-list ul li img').unveil(10);
            }
        }
    },
    ShowDetail: function (data, $detail) {
        var _this = this,
            rootPath = GetRootPath(),
            parentID = '',
            $ul;
        for (var i = 0; i < data.length; i++) {
            var it = data[i],
                $li = $detail.clone();
            if (it && it.IDKey) {
                var img = rootPath + it.Image;
                if (it.Image == '') img = _this.NoImage;

                $li.find('a').attr('href', '?ID=' + it.IDKey);
                $li.find('a img').attr({
                    'src': _this.LoadImage,
                    'data-src': img
                });
                $li.find('div').html(it.Summary);

                if ($ul == null) {
                    $ul = $('ul#' + it.ParentKey);
                }
                $ul.append($li);
            }
        }
    }
};